package com.zzptc.sky.bdsjws.activites;

import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;
import android.widget.Toast;

import com.zzptc.sky.bdsjws.R;
import com.zzptc.sky.bdsjws.activites.base.BaseActivity;
import com.zzptc.sky.bdsjws.fragments.UpdateVersionFragment;
import com.zzptc.sky.bdsjws.vo.VersionInfo;

import butterknife.BindView;
import butterknife.OnClick;

public class UpdateActivity extends BaseActivity {

    @BindView(R.id.textView2)
    TextView textView2;
    @BindView(R.id.toolbar_update)
    Toolbar tool1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(tool1);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public int getContentView() {
        return R.layout.activity_update;
    }

    @Override
    public void initData() {

    }
    @Override
    public void initView() {

    }

    @OnClick(R.id.textView2)
    public void onViewClicked() {
        //startActivity(new Intent(this,CheckUpdateActivity.class));
      startActivityForResult(new Intent(this,CheckUpdateActivity.class),0);
    }
    public void showDialog(String msg){
        FragmentManager fml=getFragmentManager();
        UpdateVersionFragment ul=UpdateVersionFragment.getUpdateVersionFragment(msg);
        ul.show(fml,"");
    }
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode){
            case 2:
                Toast.makeText(this, "断网啦 *.*", Toast.LENGTH_SHORT).show();
                showDialog("断网啦 *.*");
                break;
            case 1:
                Toast.makeText(this, "网络较慢 *.*''", Toast.LENGTH_SHORT).show();
                showDialog("网络较慢 *.*''");
                break;
            case 3:
                //Toast.makeText(this, "网络正常 0.0", Toast.LENGTH_SHORT).show();
                VersionInfo versionInfo= (VersionInfo) data.getSerializableExtra("VersionInfo");
                Toast.makeText(this,versionInfo.getApkurl()+"",Toast.LENGTH_SHORT).show();
                FragmentManager fm=getFragmentManager();
                UpdateVersionFragment u=UpdateVersionFragment.getUpdateVersionFragment(versionInfo);
                u.show(fm,"");
                break;
            case 4:
                Toast.makeText(this, "已是最新 ‘0.0’ 666", Toast.LENGTH_SHORT).show();
                showDialog("已是最新 ‘0.0’ 666");
                break;

        }
    }

}
